package com.hongawen.designmode.创建型.简单工厂模式.设计前;

import com.hongawen.designmode.创建型.简单工厂模式.UnSupportedShapeException;

/**
 * 将所有的几何图形创建都放在一个类中，通过构造方法来区分
 *
 * @author hongawen
 */
public class Diagram {

    /**
     * 类型
     */
    private String type;


    public Diagram(String type) throws UnSupportedShapeException {
        this.type = type;
        switch (type){
            case "circle":
                System.out.println("创建圆形");
                break;
            case "rectangle":
                System.out.println("创建长方形");
                break;
            case "triangle":
                System.out.println("创建三角形");
                break;
            default:
                throw new UnSupportedShapeException("没有该图形");

        }
    }

    //draw()和擦除erase()

    public void draw() throws UnSupportedShapeException {
        switch (this.type){
            case "circle":
                System.out.println("绘制圆形");
                break;
            case "rectangle":
                System.out.println("绘制长方形");
                break;
            case "triangle":
                System.out.println("绘制三角形");
                break;
            default:
                throw new UnSupportedShapeException("没有该图形");

        }
    }

    public void erase() throws UnSupportedShapeException {
        switch (this.type){
            case "circle":
                System.out.println("擦除圆形");
                break;
            case "rectangle":
                System.out.println("擦除长方形");
                break;
            case "triangle":
                System.out.println("擦除三角形");
                break;
            default:
                throw new UnSupportedShapeException("没有该图形");
        }
    }


}
